#include "chatframe.h"
#include "immgr.h"
#include "qtextedit.h"
#include "qstring.h"

chatframe::chatframe(QWidget *parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);

	connect(ui.sendmsg, SIGNAL(clicked()), SLOT(OnSendMsg()));
}

chatframe::~chatframe()
{
	
}

void chatframe::OnSendMsg()
{
	QByteArray byteArray = ui.textEdit->toPlainText().toUtf8();
	const char * text = byteArray.data();
	st_stru16 msg;
	Util::Convert::StringUTF82UTF16(text, strlen(text), msg);
	immgr::getInstance()->sendMsg(uin, msg);	
}

void chatframe::setUin( UINT64 _uin )
{
	uin = _uin;
	st_str str;
	Util::Convert::DWordToString(uin, str);
	ui.uin->setText(str.c_str());

	TXCComPtr<user_info> userInfo;
	immgr::getInstance()->queryBuddyInfo(uin, &userInfo);
	
	if (userInfo->strRealName.pstr) {
		ui.nick->setText(QString::fromUtf16(userInfo->strRealName.pstr));
	}
	else if (userInfo->strNick.pstr) {
		ui.nick->setText(QString::fromUtf16(userInfo->strNick.pstr));
	}
	else
		ui.nick->setText("");

	if (userInfo->strEmail.pstr)
		ui.email->setText(QString::fromUtf16(userInfo->strEmail.pstr));
}